<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />


<atleap:prepareMenu name="FrontendMenu" var="frontendMenu" scope="request" />

<atleap:iterator items="${frontendMenu.componentsAsPlainList}" var="item" scope="request" statusVar="status" statusScope="request">
    <c:set var="itemId" value="${item.ident}" />
    <c:choose>
        <c:when test="${status.first}">
            <div id="${frontendMenu.ident}">
                <atleap:iterator items="${item.components}" var="item" scope="request" statusVar="loopStatus" statusScope="request">
                    <jsp:include page="/WEB-INF/pages/core/frontendMenuItem.jsp" />
                </atleap:iterator>
            </div>
        </c:when>
        <c:otherwise>
            <c:set var="menuClassName" value="dropDownMenu" />
            <c:if test="${empty item.components}">
                <c:set var="className" value="dropDownMenu_empty" />
            </c:if>
            <div class="${menuClassName}" id="${itemId}__childItems" style="position: absolute; visibility: hidden">
                <atleap:iterator items="${item.components}" var="item" scope="request" statusVar="loopStatus" statusScope="request">
                    <jsp:include page="/WEB-INF/pages/core/frontendMenuItem.jsp" />
                </atleap:iterator>
            </div>
        </c:otherwise>
    </c:choose>
</atleap:iterator>

<%-- Convert server-side menu objects to Javascript --%>
<script language="javascript" type="text/javascript">
    // create holder
    var ${frontendMenu.ident} = new DropdownMenuHolder();
    ${frontendMenu.ident}.setMenu(${frontendMenu.javascriptCode});
    // save holder in array of dropdown menus
    dropdownMenus[dropdownMenus.length] = ${frontendMenu.ident};
</script>
